﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SGS.Utility
{
    public class FlagSwitchHelper<T, TResult> //where TResult : new()
    {
        public static List<TResult> Switch( T source, Dictionary<T, Func<List<TResult>>> dict )
        {
            List<TResult> list = new List<TResult>();

            int sourceInt = (int)Convert.ChangeType( source, typeof( int ) );

            foreach (var entity in dict)
            {
                int keyInt = (int)Convert.ChangeType( entity.Key, typeof( int ) );

                if ((sourceInt & keyInt) == keyInt)
                {
                    list.AddRange( entity.Value() );
                }
            }

            return list;
        }
    }
}
